/**
 * Created by Administrator on 2017/3/17 0017.
 */
Page4={
    Create:function(){
        var page={};
        var whole=new PIXI.DisplayObjectContainer();
        var triangle=new PIXI.DisplayObjectContainer();
        var triangleMask=PSP("page4_3");
        triangleMask.anchor.set(0.5,0);
        triangleMask.x=triangleMask.width/2;
        triangle.mask=triangleMask;
        var bg=PSP("page4_2");



        var sir=PSP("page4_1");
        var pink=PSP("page4_3");
        pink.anchor.set(0.5);
        pink.blendMode=PIXI.BLEND_MODES.MULTIPLY;
        var pinkMask=new PIXI.Graphics();
        pinkMask.beginFill(0x000000,1);
        pinkMask.drawRect(0,0,740,1136);
        pink.mask=pinkMask;
        var word1=PSP("page4_4");
        var word2=PSP("page4_5");
        var word3=PSP("page4_6");
        var title1=PSP("page4_7");
        var title2=PSP("page4_8");
        var title3=PSP("page4_9");
        var title4=PSP("page4_10");
        var bottom=PSP("page4_11");
        var word4=PSP("page4_12");
        var word5=PSP("page4_13");

        sir.anchor.set(0.5)
        sir.x=320+sir.width/2;sir.y=621+sir.height/2;
        pink.x=pink.width/2;pink.y=pink.height/2;
        pinkMask.x=0;pinkMask.y=974;
        word1.x=247;word1.y=536;
        word2.x=247;word2.y=502;
        word3.x=247;word3.y=467;
        title1.x=174;title1.y=318;
        title2.x=174;title2.y=212;
        title3.anchor.set(0.5,1);
        title3.x=569+title3.width/2;title3.y=212+title3.height;
        title4.x=286;title4.y=43;
        bottom.x=259;bottom.y=1050;
        word4.x=285;word4.y=477;
        word5.x=241;word5.y=518;

        whole.addChild(bg);
        whole.addChild(pink);
        whole.addChild(pinkMask);
        whole.addChild(sir);
        triangle.addChild(word1);
        triangle.addChild(word2);
        triangle.addChild(word3);
        triangle.addChild(word4);
        triangle.addChild(word5);
        triangle.addChild(title1);
        triangle.addChild(title2);
        triangle.addChild(title3);
        triangle.addChild(title4);
        whole.addChild(triangle);
        whole.addChild(triangleMask);


        bg.alpha=0;
        sir.alpha=0;
        pink.alpha=0;
        word1.alpha=0;
        word2.alpha=0;
        word3.alpha=0;
        word4.alpha=0;
        word5.alpha=0;
        title1.alpha=0;
        title2.alpha=0;
        title3.alpha=0;
        title4.alpha=0;
        bottom.alpha=0;

        var arr_sirPiece=[];
        sirPiece();
        whole.addChild(bottom);
        function sirPiece(){
            for(var i=0;i<16;i++){
                for(var j=0;j<48;j++){
                    var texture=PSP("page4_1").texture.clone();
                    var square=new PIXI.Rectangle(i*10,j*10,10,10);
                    texture.frame=square;
                    var piece=new PIXI.Sprite(texture);
                    piece.x=320+i*10;
                    piece.y=621+j*10;
                    // piece.x=Math.random()*740;
                    // piece.y=Math.random()*1136;
                    piece.alpha=0;
                    // piece.blendMode=PIXI.BLEND_MODES.MULTIPLY;
                    whole.addChild(piece);
                    arr_sirPiece.push(piece);
                }
            }
        }

        function sirCombine(){
            for(var z=0;z<arr_sirPiece.length;z++){
                var xx=320+z/48*10;
                var yy=621+z%48*10;
                // TweenMax.to(arr_sirPiece[z],0.01,{delay:1,alpha:1});
                TweenMax.to(arr_sirPiece[z],0.7+Math.random()*1,{delay:0.01+1,alpha:1,x:xx,y:yy,ease:Cubic.easeInOut});
            }
        }
        function sirSplit(){
            for(var z=0;z<arr_sirPiece.length;z++){
                var xx=arr_sirPiece[z].x-Math.random()*400+200;
                var yy=arr_sirPiece[z].y-Math.random()*400+200;
                TweenMax.to(arr_sirPiece[z],0.01,{alpha:1});
                TweenMax.to(arr_sirPiece[z],0.7+Math.random()*1,{delay:0.01,alpha:0,x:xx,y:yy,ease:Cubic.easeInOut});
            }
        }


        whole.on("pointerdown",function(){
            whole.interactive=false;
            TweenMax.killTweensOf(word4);
            TweenMax.killTweensOf(word5);
            TweenMax.to(word4,0.5,{alpha:0,ease:Cubic.easeOut});
            TweenMax.to(word5,0.5,{alpha:0,ease:Cubic.easeOut});
            TweenMax.to(bottom,0.5,{alpha:0,ease:Cubic.easeOut});
            TweenMax.to(pink.scale,1.5,{x:0,ease:Back.easeIn});
            TweenMax.to(triangleMask,1.5,{width:0,ease:Back.easeIn});
            TweenMax.to(bg,0.5,{alpha:0});
            sirSplit();
            document.dispatchEvent(new CustomEvent("PageChange",{detail:5}));
        });




        page.start=function(){
            setTimeout(function(){
                whole.interactive=true;
            },5000)

            sirCombine();
            pink.alpha=1;
            TweenMax.to(pinkMask,0.7,{delay:1,y:0,ease:Cubic.easeOut});
            TweenMax.to(bg,0.7,{delay:1.2,alpha:1,ease:Cubic.easeOut});

            word1.y+=40;
            word2.y+=35;
            word3.y+=30;
            TweenMax.to(bottom,1,{delay:2,alpha:1});


            TweenMax.to(word1,0.7,{delay:1,alpha:1,y:word1.y-40,ease:Cubic.easeOut});
            TweenMax.to(word2,0.7,{delay:1.2,alpha:1,y:word2.y-35,ease:Cubic.easeOut});
            TweenMax.to(word3,0.7,{delay:1.4,alpha:1,y:word3.y-30,ease:Cubic.easeOut});

            title1.y+=40;
            title2.y+=35;
            title3.y+=30;
            title4.y+=25;
            TweenMax.to(title1,0.7,{delay:1.6,alpha:1,y:title1.y-40,ease:Cubic.easeOut});
            TweenMax.to(title2,0.7,{delay:1.7,alpha:1,y:title2.y-35,ease:Cubic.easeOut});
            TweenMax.to(title3,0.7,{delay:1.8,alpha:1,y:title3.y-30,ease:Cubic.easeOut});
            TweenMax.to(title4,0.7,{delay:1.9,alpha:1,y:title4.y-25,ease:Cubic.easeOut});

            TweenMax.to(title3,1,{delay:2.3,rotation:Math.PI/180*15,yoyo:true,repeat:-1,ease:Cubic.easeOut});



            TweenMax.to(word1,0.7,{delay:4.0,alpha:0,y:502,ease:Cubic.easeOut});
            TweenMax.to(word2,0.7,{delay:4.0,alpha:0,y:502,ease:Cubic.easeOut});
            TweenMax.to(word3,0.7,{delay:4.0,alpha:0,y:502,ease:Cubic.easeOut});
            word4.y+=20;
            word5.y-=20;
            TweenMax.to(word4,0.7,{delay:4.3,alpha:1,y:word4.y-20,yoyo:true,repeat:-1,ease:Cubic.easeOut});
            TweenMax.to(word5,0.7,{delay:4.3,alpha:1,y:word5.y+20,yoyo:true,repeat:-1,ease:Cubic.easeOut});

        }

        page.In=function(){

        }
        page.Out=function(){

        }
        page.ReturnWhole=function(){
            return whole;
        }
        return page;
    }
}
